/**
 * 
 */
package de.idgard.android.addon.js;

import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author <a href="mailto:vesko.georgiev@uniscon.com">Vesko Georgiev</a>
 */
public class ProfileSelection extends JSONObject {

	public static enum Status {
		/** No profiles were found for this site */
		EMPTY, 
		/** The site has profiles, but the dialog was canceled */
		CANCELED, 
		/** Error occurred */
		ERROR,
		/** The site has profiles and one has been selected */
		SELECTED 
	}

	public static ProfileSelection empty() {
		return new ProfileSelection(Status.EMPTY);
	}

	public static ProfileSelection cancel() {
		return new ProfileSelection(Status.CANCELED);
	}

	public static ProfileSelection error() {
		return new ProfileSelection(Status.ERROR);
	}

	public static ProfileSelection selected(String username, String token) {
		return new ProfileSelection(Status.SELECTED, username, token);
	}

	private ProfileSelection(Status status, String username, String token) {
		try {
			put("status", status.toString());
			put("username", username);
			put("token", token);
		}
		catch (JSONException e) {
			e.printStackTrace();
		}
	}

	private ProfileSelection(Status status) {
		try {
			put("status", status.toString());
		}
		catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public String getToken() {
		return optString("token");
	}

	public String getUsername() {
		return optString("username");
	}
}
